import os
from utils import doc_util, read_config, json_util
from database.mysqlhelper import MySqLHelper

base_path = read_config.base_path
config_path = os.path.join(read_config.data_path, 'common', 'config')

# logger = Logger('突破均线任务1').get_log()
db = MySqLHelper()


# 初始化所有股票
def init_stock_info():
    stock_dict = doc_util.get_a_doc_dict(os.path.join(config_path, '0.股票信息'), 'code')
    # 增加多条
    sql3 = 'insert into t_stock_info (f_code,f_name,f_exchage,f_total_hand) VALUES (%s, %s, %s, %s)'
    li = []
    for key in stock_dict:
        stock_info = json_util.to_json(stock_dict[key])
        li.append((stock_info['code'], stock_info['name'], stock_info['exchange'], 0))
    count = db.insertmany(sql3, li)
    print(count)


# 初始化所有股票
def init_stock_d_k():
    stock_dict = doc_util.get_a_doc_dict(os.path.join(config_path, '0.股票信息'), 'code')
    # 增加多条
    sql3 = 'insert into t_stock_info (f_code,f_name,f_exchage,f_total_hand) VALUES (%s, %s, %s, %s)'
    li = []
    for key in stock_dict:
        stock_info = json_util.to_json(stock_dict[key])
        li.append((stock_info['code'], stock_info['name'], stock_info['exchange'], 0))
    count = db.insertmany(sql3, li)
    print(count)


if __name__ == '__main__':
    init_stock_info()
